<template>
    <div class="flex-container">
        <div class="flex-group">
            <div class="flex-group__wrap">
                <div class="wrap-title">今日总数</div>
                <div class="wrap-text">{{ total }} 人数</div>
            </div>
        </div>
        <div class="flex-main">
            <div class="flex-main__warp" v-for="item in listData" :key="item.accountId">
                <div class="wrap-head">
                    <div class="wrap-head__title">用户名称</div>
                    <div class="wrap-head__text">今日总数</div>
                </div>
                <div class="wrap-content">
                    <div class="wrap-content__title">{{ item.username }}</div>
                    <div class="wrap-content__text">{{ item.total }}</div>
                </div>
            </div>
        </div>
        <div class="flex-eCharts">
            <ECharts />
        </div>
    </div>
</template>

<script setup name="Index">
import { onMounted, ref } from 'vue'
import { dataAnalysis } from '@/api/index'
import ECharts from './dashboard/ECharts.vue'

onMounted(() => {
    getData()
})

const total = ref(0)
const listData = ref([])

const getData = () => {
    dataAnalysis().then(({ result }) => {
        total.value = result.map((item) => item.total).reduce((accumulator, currentValue) => accumulator + currentValue, 0)
        listData.value = result
    })
}
</script>

<style scoped lang="scss">
.flex-container {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 20px;
    .flex-group {
        box-sizing: border-box;
        padding: 10px 20px;
        box-shadow: 2px 2px 12px 2px rgba(0, 0, 0, 0.1);
        border-radius: 5px;
        &__wrap {
            .wrap-title {
                font-weight: bold;
                font-size: 18px;
            }
            .wrap-text {
                margin-top: 38px;
                color: #222;
            }
        }
    }
    .flex-eCharts {
        width: 100%;
        margin-top: 28px;
    }
    .flex-main {
        display: flex;
        margin-top: 12px;
        flex-wrap: wrap;
        &__warp {
            width: 24%;
            box-shadow: 2px 2px 12px 2px #0000001a;
            border-radius: 5px;
            padding: 10px 20px;
            margin-left: 1.3%;
            &:nth-child(4n + 1) {
                margin-left: 0;
            }
            &:nth-child(n + 5) {
                margin-top: 12px;
            }
            .wrap-head {
                display: flex;
                justify-content: space-between;

                &__title {
                    font-size: 18px;
                    font-weight: bold;
                }
                &__text {
                    font-weight: bold;
                    color: #222;
                }
            }
            .wrap-content {
                margin-top: 38px;
                display: flex;
                justify-content: space-between;
            }
        }
    }
}
</style>
